<template>
  <div class="companyInfo pageContent">
    <!-- <div style="margin-bottom:20px">
      <a-button type="primary" @click="onEdit()">编辑</a-button>
    </div>-->

    <div class="divPadding flexBetween">
      <div class="unitTitle">{{this.formUnit.orgName}}</div>
      <!-- <div class="unitTitle" v-if="!addPart1">单位信息</div> -->
      <div v-if="addPart1">
        <a-dropdown-button>
          <a-menu slot="overlay" @click="handleUnit">
            <a-menu-item key="1">
              <a-icon type="edit" />编辑
            </a-menu-item>
            <a-menu-item key="2">
              <a-icon type="delete" />删除
            </a-menu-item>
          </a-menu>
        </a-dropdown-button>
      </div>
    </div>
    <!-- 表单 -->
    <div class="aform divPadding">
      <a-form-model
        ref="ruleForm"
        layout="inline"
        :model="formUnit"
        labelAlign="left"
        v-if="addPart1"
      >
        <a-form-model-item label="统一社会信用代码" style="width:33%">{{formUnit.creditCode}}</a-form-model-item>
        <a-form-model-item label="工程专业" style="width:33%">{{formUnit.major}}</a-form-model-item>
        <a-form-model-item label="工程造价" style="width:33%">{{formUnit.cost}}亿元</a-form-model-item>
        <a-form-model-item label="建设规模" style="width:33%">{{formUnit.scale}}km</a-form-model-item>
        <a-form-model-item
          ref="time"
          label="开工时间"
          prop="time"
          style="width:33%"
        >{{formUnit.startTime}}</a-form-model-item>
        <a-form-model-item label="计划完工时间" style="width:33%">{{formUnit.endTime}}</a-form-model-item>
        <a-form-model-item label="建设周期" style="width:33%">{{formUnit.buildingPeriod}}月</a-form-model-item>

        <a-form-model-item label="项目经理" style="width:33%">{{formUnit.projectManagerFullName}}</a-form-model-item>

        <a-form-model-item label="劳资专管员" style="width:33%">{{formUnit.laborManagerFullName}}</a-form-model-item>
      </a-form-model>
      <div v-if="!addPart1" style="text-align:center;padding:40px 0px">
        <div style="margin-bottom:10px">当前还没有填写单位信息</div>
        <div style="color:#1890ff;cursor: pointer;" @click="add1">点击添加</div>
      </div>
    </div>

    <div class="divPadding flexBetween">
      <div style="line-height: 100%;">合同信息</div>
      <div v-if="addPart2">
        <a-dropdown-button>
          <a-menu slot="overlay" @click="handleUnit">
            <a-menu-item key="3">
              <a-icon type="edit" />编辑
            </a-menu-item>
            <a-menu-item key="4">
              <a-icon type="delete" />删除
            </a-menu-item>
          </a-menu>
        </a-dropdown-button>
      </div>
    </div>
    <!-- 表单 -->
    <div class="contractform divPadding">
      <a-form-model v-if="addPart2" layout="inline" :model="formContract" labelAlign="left" :label-col="labelCol"
            :wrapper-col="wrapperCol">
        <a-form-model-item ref="notice" label="中标通知书" style="width:33%">
          
            <div
            style="color:#1890ff;cursor: pointer;"
            @click="pdfModal(formUnit.bidNoticeUrl)"
          >{{this.formUnit.bidNoticeName}}</div>
        
          
        </a-form-model-item>
        <a-form-model-item ref="contract" label="施工合同" style="width:33%">
          <div
            style="color:#1890ff;cursor: pointer;"
            @click="pdfModal(formUnit.constructionContractUrl)"
          >{{this.formUnit.constructionContractName}}</div>
        </a-form-model-item>
        <a-form-model-item ref="pay" label="支付担保合同" style="width:33%" :label-col="labelCol2">
          <div
            style="color:#1890ff;cursor: pointer;"
            @click="pdfModal(formUnit.guaranteeContracUrl)"
          >{{this.formUnit.guaranteeContracName}}</div>
        </a-form-model-item>
      </a-form-model>
      <div v-if="!addPart2" style="text-align:center;padding:20px 0px">
        <!-- <div style="margin-bottom:10px">当前还没有填写单位信息</div> -->
        <div style="color:#1890ff;cursor: pointer;" @click="add2">点击添加</div>
      </div>
    </div>
    <div class="divPadding flexBetween">
      <div style="line-height: 100%;">工资支付专户信息</div>
      <div v-if="addPart3">
        <a-dropdown-button>
          <a-menu slot="overlay" @click="handleUnit">
            <a-menu-item key="5">
              <a-icon type="edit" />编辑
            </a-menu-item>
            <a-menu-item key="6">
              <a-icon type="delete" />删除
            </a-menu-item>
          </a-menu>
        </a-dropdown-button>
      </div>
    </div>
    <!-- 表单 -->
    <div class="contractform divPadding">
      <a-form-model v-if="addPart3" layout="inline" :model="formWage" labelAlign="left" :label-col="labelCol"
            :wrapper-col="wrapperCol">
        <a-form-model-item ref="bank" label="专户银行" style="width:33%">
          <span>{{this.formUnit.accountBank}}</span>
        </a-form-model-item>
        <a-form-model-item ref="account" label="专户账号" style="width:33%">
          <span>{{this.formUnit.accountNumber}}</span>
        </a-form-model-item>
        <a-form-model-item ref="voucher" label="开户凭证" style="width:33%">
          <div
            style="color:#1890ff;cursor: pointer;"
            @click="pdfModal(formUnit.accountVoucherUrl)"
          >{{this.formUnit.accountVoucherName}}</div>
        </a-form-model-item>
      </a-form-model>
      <div v-if="!addPart3" style="text-align:center;padding:20px 0px">
        <!-- <div style="margin-bottom:10px">当前还没有填写单位信息</div> -->
        <div style="color:#1890ff;cursor: pointer;" @click="add3">点击添加</div>
      </div>
    </div>
    <!-- 对话框 -->
    <div>
      <a-modal
        v-model="visible"
        :title="modalTitle"
        @ok="handleOk"
        :maskClosable="false"
        cancelText="取消"
        okText="确认"
        class="aModal"
        :centered="true"
      >
        <div v-if="isModalName=='编辑单位信息'||isModalName=='新增单位信息'">
          <a-form-model ref="ruleForm2" :model="formModal" :rules="rules" v-if="visible">
            <!-- :label-col="labelCol"
            :wrapper-col="wrapperCol"-->
            <a-form-model-item ref="orgName" label="单位名称">
              <a-input v-model="formModal.orgName" :maxLength="30" placeholder="请输入单位名称" disabled />
            </a-form-model-item>
            <a-form-model-item ref="engineering" label="工程专业" prop="engineering">
              <a-select
                label-in-value
                :defaultValue="defaultValue"
                @change="selectChange"
                placeholder="请选择"
              >
                <!-- v-model="formModal.engineering" -->
                <!--  -->
                <a-select-option
                  v-for="(item,index) in engineering "
                  :key="index"
                  :value="item.key"
                >{{item.label}}</a-select-option>
              </a-select>
            </a-form-model-item>

            <a-form-model-item ref="creditCode" label="统一社会信用代码" prop="creditCode">
              <a-input v-model="formModal.creditCode" :maxLength="30" placeholder="请输入统一社会信用代码" />
            </a-form-model-item>
            <a-form-model-item ref="cost" label="工程造价（亿元）" prop="cost">
              <a-input v-model="formModal.cost" :maxLength="30" placeholder="请输入工程造价（亿元）" />
            </a-form-model-item>
            <a-form-model-item ref="scale" label="建设规模（km）" prop="scale">
              <a-input v-model="formModal.scale" :maxLength="30" placeholder="请输入建设规模（km）" />
            </a-form-model-item>
            <a-form-model-item ref="buildingPeriod" label="建设周期（月）" prop="buildingPeriod">
              <a-input v-model="formModal.buildingPeriod" :maxLength="30" placeholder="请输入建设周期" />
            </a-form-model-item>
            <a-form-model-item ref="startTime" label="开工时间" prop="startTime">
              <a-date-picker
                v-model="formModal.startTime"
                type="date"
                style="width: 100%;"
                @change="timeChange"
              />
            </a-form-model-item>
            <a-form-model-item ref="endTime" label="计划完工时间" prop="endTime">
              <a-date-picker
                v-model="formModal.endTime"
                type="date"
                style="width: 100%;"
                @change="timeChange2"
              />
            </a-form-model-item>
            <a-form-model-item ref="projectManager" label="项目经理" prop="projectManager">
              <!-- <a-input v-model="formModal.projectManager" :maxLength="30" placeholder="请输入姓名" /> -->

              <a-select
                label-in-value
                @change="selectChange2"
                placeholder="请选择项目经理"
                :defaultValue="defaultProject"
              >
                <a-select-option
                  v-for="(item,index) in projectManagerData "
                  :key="index"
                  :value="item.key"
                >{{item.label}}</a-select-option>
              </a-select>
            </a-form-model-item>
            <a-form-model-item ref="laborManager" label="劳资专管员" prop="laborManager">
              <!-- <a-input v-model="formModal.laborManager" :maxLength="30" placeholder="请输入劳资专管员姓名" /> -->
              <a-select
                label-in-value
                @change="selectChange3"
                placeholder="请选择劳资专管员"
                :defaultValue="defaultLabor"
              >
                <a-select-option
                  v-for="(item,index) in laborManagerData "
                  :key="index"
                  :value="item.key"
                >{{item.label}}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-form-model>
        </div>
        <div v-if="isModalName=='编辑合同信息'||isModalName=='新增合同信息'">
          <a-form-model ref="ruleForm3" :model="formModal" v-if="visible">
            <!-- :label-col="labelCol"
            :wrapper-col="wrapperCol"-->
            <a-form-model-item label="中标通知书">
              <a-upload
                name="file1"
                accept=".pdf"
                :remove="handleRemove"
                :before-upload="beforeUpload"
                :show-upload-list="false"
              >
                <!-- :default-file-list="defaultFileList1" -->
                <div v-if="this.formContract.fileInfoList1.length<1">
                  <a-button @click="uploadName='中标通知书'">
                    <a-icon type="upload" />上传文件
                  </a-button>
                  <div style="color:#ccc">请上传pdf文件</div>
                </div>
              </a-upload>
              <a-spin :spinning="spinning1">
                <div
                  v-for="(item,index) in formContract.fileInfoList1"
                  :key="index"
                  class="pdfList"
                >
                  <a-icon type="file-pdf" style="color:#1890ff;margin-right:20px" />
                  <span style="margin-right:20px">{{item.name}}</span>
                  <a-icon type="delete" class="delete" @click="pdfDelete(item.uid,1)" />
                </div>
              </a-spin>
            </a-form-model-item>
            <a-form-model-item label="施工合同">
              <a-upload
                name="file2"
                accept=".pdf"
                :remove="handleRemove2"
                :before-upload="beforeUpload2"
                :show-upload-list="false"
              >
                <div v-if="this.formContract.fileInfoList2.length<1">
                  <a-button @click="uploadName='施工合同'">
                    <a-icon type="upload" />上传文件
                  </a-button>
                  <div style="color:#ccc">请上传pdf文件</div>
                </div>
              </a-upload>
              <a-spin :spinning="spinning2">
                <div
                  v-for="(item,index) in formContract.fileInfoList2"
                  :key="index"
                  class="pdfList"
                >
                  <a-icon type="file-pdf" style="color:#1890ff;margin-right:20px" />
                  <span style="margin-right:20px">{{item.name}}</span>
                  <a-icon type="delete" class="delete" @click="pdfDelete(item.uid,2)" />
                </div>
              </a-spin>
            </a-form-model-item>
            <a-form-model-item label="支付担保合同（或者保函、银行授信材料）">
              <a-upload
                name="file3"
                accept=".pdf"
                :remove="handleRemove3"
                :before-upload="beforeUpload3"
                :show-upload-list="false"
              >
                <div v-if="this.formContract.fileInfoList3.length<1">
                  <a-button @click="uploadName='支付担保合同'">
                    <a-icon type="upload" />上传文件
                  </a-button>
                  <div style="color:#ccc">请上传pdf文件</div>
                </div>
              </a-upload>
              <a-spin :spinning="spinning3">
                <div
                  v-for="(item,index) in formContract.fileInfoList3"
                  :key="index"
                  class="pdfList"
                >
                  <a-icon type="file-pdf" style="color:#1890ff;margin-right:20px" />
                  <span style="margin-right:20px">{{item.name}}</span>
                  <a-icon type="delete" class="delete" @click="pdfDelete(item.uid,3)" />
                </div>
              </a-spin>
            </a-form-model-item>
          </a-form-model>
        </div>
        <div v-if="isModalName=='编辑工资支付专户信息'||isModalName=='新增工资支付专户信息'">
          <a-form-model ref="ruleForm4" :model="formModal" v-if="visible">
            <!-- :label-col="labelCol"
            :wrapper-col="wrapperCol"-->
            <a-form-model-item label="工资专户银行">
              <a-input v-model="formModal.accountBank" :maxLength="30" placeholder="请输入工资专户银行" />
            </a-form-model-item>
            <a-form-model-item ref="code" label="专户账号" prop="code">
              <a-input v-model="formModal.accountNumber" :maxLength="30" placeholder="请输入专户账号" />
            </a-form-model-item>
            <a-form-model-item label="开户凭证" prop="formUpload2">
              <a-upload
                name="file"
                accept=".pdf"
                :remove="handleRemove4"
                :before-upload="beforeUpload4"
                :show-upload-list="false"
              >
                <div v-if="this.formWage.fileInfoList4.length<1">
                  <a-button @click="uploadName='开户凭证'">
                    <a-icon type="upload" />上传文件
                  </a-button>
                  <div style="color:#ccc">请上传pdf文件</div>
                </div>
              </a-upload>
              <a-spin :spinning="spinning4">
                <div v-for="(item,index) in formWage.fileInfoList4" :key="index" class="pdfList">
                  <a-icon type="file-pdf" style="color:#1890ff;margin-right:20px" />
                  <span style="margin-right:20px">{{item.name}}</span>
                  <a-icon type="delete" class="delete" @click="pdfDelete(item.uid,4)" />
                </div>
              </a-spin>
            </a-form-model-item>
          </a-form-model>
        </div>
      </a-modal>
    </div>

    <!-- pdf对话框 -->
    <div>
      <a-modal
        v-model="visiblePdf"
        title
        @ok="handleOkPdf"
        :footer="null"
        :maskClosable="false"
        width="1080px"
        :centered="true"
        :bodyStyle="{textAlign:'center'}"
        v-if="visiblePdf"
        key="modalpdf"
      >
        <embed v-if="visiblePdf" width="1000" height="700" :src="this.pdfUrl" type />
      </a-modal>
    </div>
  </div>
</template>

<script>
import { uploadOSS } from '@/utils/oss.js'
import { message } from 'ant-design-vue'
import { mapGetters } from 'vuex'
import {
  addOrgSubsidiaryInfo,
  queryMajor,
  getOrgSubsidiaryInfo,
  updateOrgSubsidiaryInfo,
  deleteOrgSubsidiaryInfo,
  deleteAccountVoucher,
  deleteContract,
  queryManager
} from '@/api/unitInfo.js'
import moment from 'moment'
export default {
  data() {
    return {
      labelCol: { span:7},
      labelCol2: { span: 8},
      wrapperCol: { span: 14 },
      orgName: '',
      formUnit: {
        major: '',
        engineering: '',
        code: '',
        cost: '',
        scale: '',
        startTime: '',
        endTime: '',
        cycle: '',
        pr: '',
        orgName: '',
        creditCode: '',
        buildingPeriod: '',
        projectManagerFullName: '',
        projectManagerPersonId: '',
        laborManagerFullName: '',
        laborManagerPersonId: '',
        guaranteeContracName: '',
        projectManager: '',
        laborManager: '',
        constructionContractName: '',
        bidNoticeName: '',
        guaranteeContracUrl: '',
        constructionContractUrl: '',
        bidNoticeUrl: ''
      },
      formContract: {
        fileInfoList1: [],
        fileInfoList2: [],
        fileInfoList3: []
      },
      defaultFileList3: [],
      defaultFileList2: [],
      defaultFileList1: [],
      defaultFileList4: [],
      spinning1: false,
      spinning2: false,
      spinning3: false,
      spinning4: false,
      formWage: {
        accountBank: '建设银行',
        accountNumber: '10383000000216268',
        voucher: '开户凭证.pdf',
        fileInfoList4: []
      },
      formModal: {
        major: '',
        engineering: '',
        code: '9192K322W2113I',
        cost: '',
        scale: '10.65km',
        startTime: '2018-03-01',
        endTime: '2021-03-01',
        cycle: '33月',
        pr: '张三',
        orgName: '',
        creditCode: '',
        buildingPeriod: '',
        projectManagerFullName: '',
        projectManagerPersonId: '',
        laborManagerFullName: '',
        laborManagerPersonId: ''
      },
      rules: {
        orgName: [
          {
            required: true,
            message: '请输入单位名称',
            trigger: 'change'
          }
        ],
        scale: [
          {
            required: true,
            message: '请输入建设规模',
            trigger: 'change'
          },
          {
            pattern: new RegExp(/^[0-9]+([.]{1}[0-9]+){0,1}$/),
            message: '请输入整数或小数',
            trigger: 'change'
          }
        ],
        cost: [
          {
            required: true,
            message: '请输入工程造价',
            trigger: 'change'
          },
          {
            pattern: new RegExp(/^[0-9]+([.]{1}[0-9]+){0,1}$/),
            message: '请输入整数或小数',
            trigger: 'change'
          }
        ],
        buildingPeriod: [
          {
            required: true,
            message: '请输入周期',
            trigger: 'change'
          },
          {
            pattern: new RegExp(/^[0-9]\d*$/),
            message: '请输入整数',
            trigger: 'change'
          }
        ]
      },
      visible: false,
      defaultValue: { key: '' },
      defaultLabor: { key: '' },
      defaultProject: { key: '' },
      engineering: [],
      isModalName: '',
      modalTitle: '',
      uploadName: '',
      addPart1: false,
      addPart2: false,
      addPart3: false,
      visiblePdf: false,
      pdfUrl: '',
      isAdd: false,
      projectManagerData: [],
      laborManagerData: []
    }
  },
  mounted() {
    this.getManageInfo()
    queryMajor({ typeName: '工程专业' }).then((res) => {
      // console.log(res.data.data);
      let data = res.data.data
      data.forEach((item) => {
        item.key = item.type
        item.label = item.value
      })
      this.engineering = data
    })
    // this.getForm()

    // console.log(this.userInfo);
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    moment,
    // 查询所有信息
    getForm() {
      this.formContract.fileInfoList1 = []
      this.formContract.fileInfoList2 = []
      this.formContract.fileInfoList3 = []
      this.formWage.fileInfoList4 = []

      this.defaultFileList3 = []
      this.defaultFileList2 = []
      this.defaultFileList1 = []
      this.defaultFileList4 = []
      let id = this.userInfo.orgId
      getOrgSubsidiaryInfo({ orgId: id }).then((res) => {
        if (res.data.data.startTime != null) {
          res.data.data.startTime = moment(res.data.data.startTime)
        }
        if (res.data.data.endTime != null) {
          res.data.data.endTime = moment(res.data.data.endTime)
        }

        this.formUnit = res.data.data
        this.orgName = this.formUnit.orgName
        this.formModal.orgName = this.formUnit.orgName
        // this.$forceUpdate()
        if (this.formUnit.bidNoticeName != '' && this.formUnit.bidNoticeName != null) {
          this.formContract.fileInfoList1.push({
            name: this.formUnit.bidNoticeName,
            url: this.formUnit.bidNoticeUrl,
            uid: this.formUnit.bidNoticeUrl,
            status: 'done'
          })
          this.defaultFileList1 = this.formContract.fileInfoList1
        }
        if (this.formUnit.constructionContractName != '' && this.formUnit.constructionContractName != null) {
          this.formContract.fileInfoList2.push({
            name: this.formUnit.constructionContractName,
            url: this.formUnit.constructionContractUrl,
            uid: this.formUnit.constructionContractUrl,
            status: 'done'
          })
          // console.log(this.formContract.fileInfoList2)

          this.defaultFileList2 = this.formContract.fileInfoList2
          // console.log(this.defaultFileList2)
        }
        if (this.formUnit.guaranteeContracName != '' && this.formUnit.guaranteeContracName != null) {
          this.formContract.fileInfoList3.push({
            name: this.formUnit.guaranteeContracName,
            url: this.formUnit.guaranteeContracUrl,
            uid: this.formUnit.guaranteeContracUrl,
            status: 'done'
          })
          this.defaultFileList3 = this.formContract.fileInfoList3
        }
        if (this.formUnit.accountVoucherName != null && this.formUnit.accountVoucherName != '') {
          this.formWage.fileInfoList4.push({
            name: this.formUnit.accountVoucherName,
            url: this.formUnit.accountVoucherUrl,
            uid: this.formUnit.accountVoucherUrl,
            status: 'done'
          })
          this.defaultFileList4 = this.formWage.fileInfoList4
        }
        if (res.data.data.startTime != null) {
          res.data.data.startTime = moment(res.data.data.startTime).format('YYYY-MM-DD')
        }
        if (res.data.data.endTime != null) {
          res.data.data.endTime = moment(res.data.data.endTime).format('YYYY-MM-DD')
        }

        this.formModal = JSON.parse(JSON.stringify(res.data.data))
        if (this.formModal.major != null) {
          this.engineering.forEach((item) => {
            if (this.formModal.major == item.label) {
              // console.log(item.label)

              this.formModal.major = item.key
              this.defaultValue.key = item.key
            }
          })
        } else {
        }
        if (this.formModal.laborManagerFullName) {
          this.laborManagerData.forEach((item) => {
            if (this.formModal.laborManagerFullName == item.label) {
              this.defaultLabor.key = item.key
            }
          })
        } else {
        }
        if (this.formModal.projectManagerFullName) {
          this.projectManagerData.forEach((item) => {
            if (this.formModal.projectManagerFullName == item.label) {
              this.defaultProject.key = item.key
            }
          })
        } else {
        }
        // 判断单位信息是否存在
        if (this.formUnit.cost == null) {
          this.addPart1 = false
        } else {
          this.addPart1 = true
        }
        if (
          (this.formUnit.bidNoticeName == null || this.formUnit.bidNoticeName == '') &&
          (this.formUnit.constructionContractName == null || this.formUnit.constructionContractName == '') &&
          (this.formUnit.guaranteeContracName == null || this.formUnit.guaranteeContracName == '')
        ) {
          this.addPart2 = false
        } else {
          this.addPart2 = true
          // console.log(this.formUnit);
        }
        if (
          (this.formUnit.accountBank == null || this.formUnit.accountBank == '') &&
          (this.formUnit.accountNumber == null || this.formUnit.accountNumber == '') &&
          (this.formUnit.accountVoucherName == null || this.formUnit.accountVoucherName == '')
        ) {
          this.addPart3 = false
        } else {
          this.addPart3 = true
        }
        // console.log(this.formUnit );
      })
    },
    onEdit() {
      this.visible = true
    },
    selectChange(value) {
      // console.log(value);
      this.formModal.major = value.key
      this.formModal.engineering = value.label
    },
    selectChange2(value) {
      // console.log(value);
      this.formModal.projectManagerFullName = value.label
      this.formModal.projectManagerPersonId = value.key
      // console.log(this.formModal.projectManager);
    },
    selectChange3(value) {
      // console.log(value);

      this.formModal.laborManagerFullName = value.label
      this.formModal.laborManagerPersonId = value.key
    },
    // 新增信息
    handleOk() {
      switch (this.isModalName) {
        case '新增单位信息':
          this.$refs.ruleForm2.validate((valid) => {
            if (valid) {
              let data = {
                accountBank: '',
                accountNumber: '',
                accountVoucherName: '',
                accountVoucherUrl: '',
                bidNoticeName: '',
                bidNoticeUrl: '',
                buildingPeriod: this.formModal.buildingPeriod,
                constructionContractName: '',
                constructionContractUrl: '',
                cost: this.formModal.cost,
                endTime: this.formModal.endTime,
                guaranteeContracName: '',
                guaranteeContracUrl: '',
                laborManagerFullName: this.formModal.laborManagerFullName,
                laborManagerPersonId: this.formModal.laborManagerPersonId,
                projectManagerFullName: this.formModal.projectManagerFullName,
                projectManagerPersonId: this.formModal.projectManagerPersonId,
                major: this.formModal.major,
                orgId: this.userInfo.orgId,
                orgName: this.formModal.orgName,
                creditCode: this.formModal.creditCode,
                projectId: '',

                scale: this.formModal.scale,
                startTime: this.formModal.startTime
              }
              addOrgSubsidiaryInfo(data).then((res) => {
                this.visible = false
                this.$message.success('新增成功')
                this.addPart1 = true
                this.getForm()
              })
            } else {
              return false
            }
          })
          break

        case '编辑单位信息':
          // console.log(this.formUnit)

          this.formUnit.major = this.formModal.major
          this.$refs.ruleForm2.validate((valid) => {
            if (valid) {
              let data1 = {
                accountBank: this.formUnit.accountBank,
                accountNumber: this.formUnit.accountNumber,
                accountVoucherName: this.formUnit.accountVoucherName,
                accountVoucherUrl: this.formUnit.accountVoucherUrl,
                bidNoticeName: this.formUnit.bidNoticeName,
                bidNoticeUrl: this.formUnit.bidNoticeUrl,
                buildingPeriod: this.formModal.buildingPeriod,
                constructionContractName: this.formUnit.constructionContractName,
                constructionContractUrl: this.formUnit.constructionContractUrl,
                cost: this.formModal.cost,
                endTime: this.formModal.endTime,
                guaranteeContracName: this.formUnit.guaranteeContracName,
                guaranteeContracUrl: this.formUnit.guaranteeContracUrl,
                laborManagerFullName: this.formModal.laborManagerFullName,
                laborManagerPersonId: this.formModal.laborManagerPersonId,
                projectManagerFullName: this.formModal.projectManagerFullName,
                projectManagerPersonId: this.formModal.projectManagerPersonId,
                major: this.formModal.major,
                orgId: this.userInfo.orgId,
                orgName: this.formModal.orgName,
                creditCode: this.formModal.creditCode,
                projectId: '',
                scale: this.formModal.scale,
                startTime: this.formModal.startTime,
                id: this.formUnit.id
              }
              // let data1 = this.formModal
              updateOrgSubsidiaryInfo(data1).then((res) => {
                this.$message.success('编辑成功')
                this.getForm()
                this.visible = false
              })
            } else {
              return false
            }
          })
          break
        case '新增合同信息':
          if (this.spinning1 == false && this.spinning2 == false && this.spinning3 == false) {
            if (this.formContract.fileInfoList1.length == 0) {
              this.formContract.fileInfoList1.push({
                name: '',
                url: ''
              })
            }
            if (this.formContract.fileInfoList2.length == 0) {
              this.formContract.fileInfoList2.push({
                name: '',
                url: ''
              })
            }
            if (this.formContract.fileInfoList3.length == 0) {
              this.formContract.fileInfoList3.push({
                name: '',
                url: ''
              })
            }
            this.formUnit.major = this.formModal.major
            let data2 = this.formUnit
            data2.bidNoticeName = this.formContract.fileInfoList1[0].name

            data2.bidNoticeUrl = this.formContract.fileInfoList1[0].url

            data2.constructionContractName = this.formContract.fileInfoList2[0].name
            data2.constructionContractUrl = this.formContract.fileInfoList2[0].url

            data2.guaranteeContracName = this.formContract.fileInfoList3[0].name
            data2.guaranteeContracUrl = this.formContract.fileInfoList3[0].url
            updateOrgSubsidiaryInfo(data2).then((res) => {
              this.$message.success('新增成功')
              this.getForm()
              this.addPart2 = true
              this.visible = false
            })
          } else {
            this.$message.destroy()
            this.visible = true
            this.$message.success('请稍等')
          }

          // this.addPart2 = true
          break
        case '编辑合同信息':
          if (this.spinning1 == false && this.spinning2 == false && this.spinning3 == false) {
            if (this.formContract.fileInfoList1.length == 0) {
              this.formContract.fileInfoList1.push({
                name: '',
                url: ''
              })
            }
            if (this.formContract.fileInfoList2.length == 0) {
              this.formContract.fileInfoList2.push({
                name: '',
                url: ''
              })
            }
            if (this.formContract.fileInfoList3.length == 0) {
              this.formContract.fileInfoList3.push({
                name: '',
                url: ''
              })
            }
            this.formUnit.major = this.formModal.major
            let data3 = {}
            data3 = JSON.parse(JSON.stringify(this.formUnit))
            // console.log(data3)

            data3.bidNoticeName = this.formContract.fileInfoList1[0].name

            data3.bidNoticeUrl = this.formContract.fileInfoList1[0].url

            data3.constructionContractName = this.formContract.fileInfoList2[0].name
            data3.constructionContractUrl = this.formContract.fileInfoList2[0].url

            data3.guaranteeContracName = this.formContract.fileInfoList3[0].name
            data3.guaranteeContracUrl = this.formContract.fileInfoList3[0].url

            updateOrgSubsidiaryInfo(data3).then((res) => {
              this.$message.success('编辑成功')
              this.visible = false
              this.getForm()
            })
          } else {
            this.$message.destroy()
            this.visible = true
            this.$message.success('请稍等')
          }

          break
        case '新增工资支付专户信息':
          if (this.spinning4 == false) {
            if (this.formWage.fileInfoList4.length == 0) {
              this.formWage.fileInfoList4.push({
                name: '',
                url: ''
              })
            }
            this.formUnit.major = this.formModal.major
            let data4 = this.formUnit
            data4.accountVoucherName = this.formWage.fileInfoList4[0].name

            data4.accountVoucherUrl = this.formWage.fileInfoList4[0].url

            data4.accountBank = this.formModal.accountBank
            data4.accountNumber = this.formModal.accountNumber
            updateOrgSubsidiaryInfo(data4).then((res) => {
              this.$message.success('新增成功')
              this.visible = false
              this.getForm()
              this.addPart3 = true
            })
          } else {
            this.$message.destroy()
            this.visible = true
            this.$message.success('请稍等')
          }
          break
        default:
          if (this.spinning4 == false) {
            if (this.formWage.fileInfoList4.length == 0) {
              this.formWage.fileInfoList4.push({
                name: '',
                url: ''
              })
            }
            this.formUnit.major = this.formModal.major
            let data5 = this.formUnit
            data5.accountVoucherName = this.formWage.fileInfoList4[0].name

            data5.accountVoucherUrl = this.formWage.fileInfoList4[0].url

            data5.accountBank = this.formModal.accountBank
            data5.accountNumber = this.formModal.accountNumber
            updateOrgSubsidiaryInfo(data5).then((res) => {
              this.$message.success('编辑成功')
              this.visible = false
              this.getForm()
              // this.addPart3 = true
            })
          } else {
            this.$message.destroy()
            this.visible = true
            this.$message.success('请稍等')
          }
          break
      }
    },
    // 编辑信息
    handleUnit(e) {
      // console.log(e);

      switch (parseInt(e.key)) {
        case 1:
          this.getForm()
          this.isModalName = '编辑单位信息'
          this.modalTitle = '编辑单位信息'
          // this.getForm()
          this.visible = true
          break
        case 2:
          deleteOrgSubsidiaryInfo({ id: this.formUnit.id }).then((res) => {
            this.$message.success('删除成功')
            this.getForm()
            this.addPart1 = false
          })

          break
        case 3:
          this.isModalName = '编辑合同信息'
          this.modalTitle = '编辑合同信息'
          this.spinning2 = false
          // this.getForm()
          this.visible = true
          break
        case 4:
          deleteContract({ id: this.formUnit.id }).then((res) => {
            this.$message.success('删除成功')
            this.getForm()
            this.addPart2 = false
          })

          break
        case 5:
          this.isModalName = '编辑工资支付专户信息'
          this.modalTitle = '编辑工资支付专户信息'
          this.visible = true
          break
        case 6:
          deleteAccountVoucher({ id: this.formUnit.id }).then((res) => {
            this.$message.success('删除成功')
            this.getForm()
            this.addPart3 = false
          })
          break
        default:
          break
      }
    },
    handleRemove(file) {
      this.formContract.fileInfoList1.forEach((item, index) => {
        if (file.uid == item.uid) {
          this.formContract.fileInfoList1.splice(index, 1)
          this.defaultFileList1.splice(index, 1)
        }
      })
    },
    handleRemove2(file) {
      this.formContract.fileInfoList2.forEach((item, index) => {
        if (file.uid == item.uid) {
          this.formContract.fileInfoList2.splice(index, 1)
          this.defaultFileList2.splice(index, 1)
        }
      })
    },
    handleRemove3(file) {
      this.formContract.fileInfoList3.forEach((item, index) => {
        if (file.uid == item.uid) {
          this.formContract.fileInfoList3.splice(index, 1)
          this.defaultFileList3.splice(index, 1)
        }
      })
    },
    handleRemove4(file) {
      this.formWage.fileInfoList4.forEach((item, index) => {
        if (file.uid == item.uid) {
          this.formWage.fileInfoList4.splice(index, 1)
          this.defaultFileList4.splice(index, 1)
        }
      })
    },
    // 上传图片
    beforeUpload(file) {
      // console.log(file)
      if (this.configFun.pdf(file)) {
        const reader = new FileReader()
        reader.readAsDataURL(file) // 读取文件

        this.spinning1 = true

        reader.onload = (data) => {
          //  console.log(file)
          this.uploadFile(data.target.result, file.name, file.uid, file.uid)
        }
        // if (this.modalTitle == '凭证登记') {
        //   this.iswageModal = true
        // } else {
        //   this.isbankModal = true
        // }
      } else {
        // this.defaultFileList = []
        // this.flagUpload=true
        this.$message.error('你上传的不是PDF')
        return false
      }
      return false
    },
    beforeUpload2(file) {
      // console.log(file)
      if (this.configFun.pdf(file)) {
        const reader = new FileReader()
        reader.readAsDataURL(file) // 读取文件

        this.spinning2 = true

        reader.onload = (data) => {
          //  console.log(file)
          this.uploadFile2(data.target.result, file.name, file.uid, file.uid)
        }
        // if (this.modalTitle == '凭证登记') {
        //   this.iswageModal = true
        // } else {
        //   this.isbankModal = true
        // }
      } else {
        // this.defaultFileList = []
        // this.flagUpload=true
        this.$message.error('你上传的不是PDF')
        return false
      }
      return false
    },
    beforeUpload3(file) {
      // console.log(file)
      if (this.configFun.pdf(file)) {
        const reader = new FileReader()
        reader.readAsDataURL(file) // 读取文件

        this.spinning3 = true

        reader.onload = (data) => {
          //  console.log(file)
          this.uploadFile3(data.target.result, file.name, file.uid, file.uid)
        }
        // if (this.modalTitle == '凭证登记') {
        //   this.iswageModal = true
        // } else {
        //   this.isbankModal = true
        // }
      } else {
        // this.defaultFileList = []
        // this.flagUpload=true
        this.$message.error('你上传的不是PDF')
        return false
      }
      return false
    },
    beforeUpload4(file) {
      // console.log(file)
      if (this.configFun.pdf(file)) {
        const reader = new FileReader()
        reader.readAsDataURL(file) // 读取文件

        this.spinning4 = true

        reader.onload = (data) => {
          //  console.log(file)
          this.uploadFile4(data.target.result, file.name, file.uid, file.uid)
        }
        // if (this.modalTitle == '凭证登记') {
        //   this.iswageModal = true
        // } else {
        //   this.isbankModal = true
        // }
      } else {
        // this.defaultFileList = []
        // this.flagUpload=true
        this.$message.error('你上传的不是PDF')
        return false
      }
      return false
    },
    uploadFile(base64Data, fileName, fileUid, packageId) {
      // console.log(111);
      // console.log(this.uploadName);

      let blob = this.dataURLtoBlob(base64Data)
      let dir = 'lw/' + 'companyInfo' + packageId + '/'
      uploadOSS(blob, fileName, dir).then((fileUrl) => {
        // console.log(222);
        let obj = { url: fileUrl, name: fileName, uid: fileUid, status: 'done' }
        // if (this.uploadName == '中标通知书') {
        this.formContract.fileInfoList1.push(obj)
        this.spinning1 = false
        this.$message.success(`${fileName} 上传成功`, 1)
        // console.log(this.formContract.fileInfoList1)
        // }
        // else if (this.uploadName == '施工合同') {
        //   this.formContract.fileInfoList2.push(obj)
        //   this.spinning2 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '支付担保合同') {
        //   this.formContract.fileInfoList3.push(obj)
        //   this.spinning3 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '开户凭证') {
        //   // console.log(111);

        //   this.formWage.fileInfoList4.push(obj)
        //   this.spinning4 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // }
      })
    },
    uploadFile2(base64Data, fileName, fileUid, packageId) {
      // console.log(111);
      // console.log(this.uploadName);

      let blob = this.dataURLtoBlob(base64Data)
      let dir = 'lw/' + 'DO' + packageId + '/'
      uploadOSS(blob, fileName, dir).then((fileUrl) => {
        // console.log(222);
        let obj = { url: fileUrl, name: fileName, uid: fileUid, status: 'done' }
        // if (this.uploadName == '中标通知书') {
        //   this.formContract.fileInfoList1.push(obj)
        //   this.spinning1 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '施工合同') {
        this.formContract.fileInfoList2.push(obj)
        this.spinning2 = false
        this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '支付担保合同') {
        //   this.formContract.fileInfoList3.push(obj)
        //   this.spinning3 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '开户凭证') {

        //   this.formWage.fileInfoList4.push(obj)
        //   this.spinning4 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // }
      })
    },
    uploadFile3(base64Data, fileName, fileUid, packageId) {
      // console.log(111);
      // console.log(this.uploadName);

      let blob = this.dataURLtoBlob(base64Data)
      let dir = 'lw/' + 'DO' + packageId + '/'
      uploadOSS(blob, fileName, dir).then((fileUrl) => {
        // console.log(222);
        let obj = { url: fileUrl, name: fileName, uid: fileUid, status: 'done' }
        // if (this.uploadName == '中标通知书') {
        //   this.formContract.fileInfoList1.push(obj)
        //   this.spinning1 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        //   // console.log(this.formContract.fileInfoList1)
        // } else if (this.uploadName == '施工合同') {
        //   this.formContract.fileInfoList2.push(obj)
        //   this.spinning2 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '支付担保合同') {
        this.formContract.fileInfoList3.push(obj)
        this.spinning3 = false
        this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '开户凭证') {
        //   // console.log(111);

        //   this.formWage.fileInfoList4.push(obj)
        //   this.spinning4 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // }
      })
    },
    uploadFile4(base64Data, fileName, fileUid, packageId) {
      // console.log(111);
      // console.log(this.uploadName);

      let blob = this.dataURLtoBlob(base64Data)
      let dir = 'lw/' + 'DO' + packageId + '/'
      uploadOSS(blob, fileName, dir).then((fileUrl) => {
        // console.log(222);
        let obj = { url: fileUrl, name: fileName, uid: fileUid, status: 'done' }
        // if (this.uploadName == '中标通知书') {
        //   this.formContract.fileInfoList1.push(obj)
        //   this.spinning1 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        //   // console.log(this.formContract.fileInfoList1)
        // } else if (this.uploadName == '施工合同') {
        //   this.formContract.fileInfoList2.push(obj)
        //   this.spinning2 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '支付担保合同') {
        //   this.formContract.fileInfoList3.push(obj)
        //   this.spinning3 = false
        //   this.$message.success(`${fileName} 上传成功`, 1)
        // } else if (this.uploadName == '开户凭证') {
        // console.log(111);

        this.formWage.fileInfoList4.push(obj)
        this.spinning4 = false
        this.$message.success(`${fileName} 上传成功`, 1)
        // }
      })
    },
    dataURLtoBlob(dataurl) {
      var arr = dataurl.split(','),
        mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]),
        n = bstr.length,
        u8arr = new Uint8Array(n)
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
      }
      return new Blob([u8arr], {
        type: mime
      })
    },
    timeChange(val) {
      if (val != null) {
        this.formModal.startTime = moment(val).format('YYYY-MM-DD')
      } else {
        this.formModal.startTime = ''
      }
    },
    timeChange2(val) {
      if (val != null) {
        this.formModal.endTime = moment(val).format('YYYY-MM-DD')
      } else {
        this.formModal.endTime = ''
      }
    },
    add1() {
      this.isModalName = '新增单位信息'
      this.modalTitle = '新增单位信息'
      // console.log(this,fo);
      this.formModal = {}
      this.formModal.orgName = this.formUnit.orgName
      this.defaultValue = { key: '' }
      this.defaultLabor = { key: '' }
      this.defaultProject = { key: '' }
      this.visible = true
    },
    add2() {
      this.isModalName = '新增合同信息'
      this.spinning2 = false
      this.modalTitle = '新增合同信息'
      if (!this.addPart1) {
        this.$message.destroy()
        this.$message.error('请先添加单位信息')
      } else {
        this.formContract.fileInfoList1 = []
        this.formContract.fileInfoList2 = []
        this.formContract.fileInfoList3 = []
        this.defaultFileList1 = []
        this.defaultFileList2 = []
        this.defaultFileList3 = []
        this.visible = true
      }
    },
    add3() {
      this.isModalName = '新增工资支付专户信息'
      this.modalTitle = '新增工资支付专户信息'
      if (!this.addPart1) {
        this.$message.destroy()
        this.$message.error('请先添加单位信息')
      } else {
        this.visible = true
      }
    },
    pdfModal(value) {
      // console.log(value);
      if (value) {
        this.pdfUrl = value
      } else {
        this.pdfUrl = 'http://lw-sit.oss-cn-beijing.aliyuncs.com/lw/DO/1617241270460111.pdf'
      }
      this.visiblePdf = true
    },
    handleOkPdf() {
      this.visiblePdf = false
    },
    // 获取主管信息
    getManageInfo() {
      queryManager({ orgId: this.userInfo.orgId }).then((res) => {
        let data = res.data.data
        data.forEach((item, index) => {
          item.label = item.fullName
          item.key = item.personId
        })
        this.projectManagerData = data
        this.laborManagerData = data
        // console.log(data);
        this.getForm()
      })
    },
    pdfDelete(uid, flag) {
      // console.log(uid);

      switch (flag) {
        case 1:
          let findVal = this.formContract.fileInfoList1.findIndex((item) => {
            return item.uid === uid
          })
          this.formContract.fileInfoList1.splice(findVal, 1)
          break
        case 2:
          let findVal2 = this.formContract.fileInfoList2.findIndex((item) => {
            return item.uid === uid
          })
          this.formContract.fileInfoList2.splice(findVal, 1)
          break
        case 3:
          let findVal3 = this.formContract.fileInfoList3.findIndex((item) => {
            return item.uid === uid
          })
          this.formContract.fileInfoList3.splice(findVal, 1)
          break
        default:
          let findVal4 = this.formWage.fileInfoList4.findIndex((item) => {
            return item.uid === uid
          })
          this.formWage.fileInfoList4.splice(findVal, 1)
          break
      }

      // if (this.form.fileInfoList.length != 0) {
      //   // this.isUpload = true
      //   this.pdfData = true
      // } else {
      //   this.pdfData = false
      // }
    }
  }
}
</script>

<style scoped lang='less'>
.companyInfo {
  font-family: Microsoft YaHei;
  font-weight: 400;
}
.divPadding {
  margin-bottom: 20px;
  font-size: 16px;
}
.unitTitle {
  color: #000;
  font-size: 26px;
  line-height: 100%;
}

.aform,
.contractform {
  width: 100%;
  background: #f5faff;
  padding: 10px 30px;
  min-height: 100px;
}
.contractform {
  background: #f5faff;
  min-height: 60px;
}
.flexBetween {
  align-items: center;
}
::v-deep .ant-btn-group > .ant-btn:first-child:not(:last-child) {
  display: none;
}
.pdfModal {
  ::v-deep .ant-modal {
    width: 1080px !important;
    top: 20px;
  }
}
.pdfModal ::v-deep .ant-modal-body {
  padding: 40px;
  text-align: center;
  height: 780px;
}
.delete:hover {
  color: #1890ff;
  cursor: pointer;
}
.pdfList {
  padding: 5px 10px;
  border: 1px solid #ccc;
  margin: 7px 0px;
}
::v-deep .ant-upload.ant-upload-select {
  width: 100%;
}
::v-deep .ant-modal {
  padding-bottom: 0;
}
.aModal {
  ::v-deep .ant-modal-body {
    max-height: 500px;
    overflow: auto;
  }
}

.aModal {
  ::-webkit-scrollbar {
    width: 7px;
    height: 7px;
    /**/
  }
}
.aModal {
  ::-webkit-scrollbar-track {
    background: #f8f8f8;
    border-radius: 4px;
  }
}
.aModal {
  ::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 4px;
  }
}
::v-deep .ant-form-inline .ant-form-item{
  margin-right: 0;
}
</style>
